package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.SysApplications;
import com.yinhe.system.service.ISysApplicationsService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 应用权限 Controller
 * 
 * @author yinhe
 * @date 2022-07-21
 */
@RestController
@RequestMapping("/system/applications")
public class SysApplicationsController extends BaseController
{
    @Autowired
    private ISysApplicationsService sysApplicationsService;

    /**
     * 查询应用权限列表
     */
    @PreAuthorize("@ss.hasPermi('system:applications:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysApplications sysApplications)
    {
        startPage();
        List<SysApplications> list = sysApplicationsService.selectSysApplicationsList(sysApplications);
        return getDataTable(list);
    }

    /**
     * 导出应用权限列表
     */
    @PreAuthorize("@ss.hasPermi('system:applications:export')")
    @Log(title = "应用权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysApplications sysApplications)
    {
        List<SysApplications> list = sysApplicationsService.selectSysApplicationsList(sysApplications);
        ExcelUtil<SysApplications> util = new ExcelUtil<SysApplications>(SysApplications.class);
        util.exportExcel(response, list, "应用权限数据");
    }

    /**
     * 获取应用权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:applications:query')")
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable("menuId") Long menuId)
    {
        return AjaxResult.success(sysApplicationsService.selectSysApplicationsByMenuId(menuId));
    }

    /**
     * 新增应用权限
     */
    @PreAuthorize("@ss.hasPermi('system:applications:add')")
    @Log(title = "应用权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysApplications sysApplications)
    {
        return toAjax(sysApplicationsService.insertSysApplications(sysApplications));
    }

    /**
     * 修改应用权限
     */
    @PreAuthorize("@ss.hasPermi('system:applications:edit')")
    @Log(title = "应用权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysApplications sysApplications)
    {
        return toAjax(sysApplicationsService.updateSysApplications(sysApplications));
    }

    /**
     * 删除应用权限
     */
    @PreAuthorize("@ss.hasPermi('system:applications:remove')")
    @Log(title = "应用权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{menuIds}")
    public AjaxResult remove(@PathVariable Long[] menuIds)
    {
        return toAjax(sysApplicationsService.deleteSysApplicationsByMenuIds(menuIds));
    }
}
